#pragma once

#include <iostream>
#include <string>
#include <vector>
#include "ctemplate/template.h"
// #include "oj_model.hpp"
#include "oj_model2.hpp"
namespace ns_view
{
    using namespace std;
    using namespace ns_model;

    const string template_path = "./template_html/";
    class View
    {
    public:
        void AllExpandHtml(const vector<Question> &questions, string *html)
        {
            // 1.构建路径
            string path = template_path + "allquestion.html";
            // 2.构建字典
            ctemplate::TemplateDictionary root("allquestion");
            for (const auto &q : questions)
            {
                // 构建子字典用于循环遍历
                ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", q.number);
                sub->SetValue("title", q.title);
                sub->SetValue("grade", q.grade);
            }
            // 3.获取被渲染的html
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(path.c_str(), ctemplate::DO_NOT_STRIP);

            // 4.完成渲染
            tpl->Expand(html, &root);
        }

        void OneExpandHtml(const Question &q, string *html)
        {

            //1.构建路径
            string path = template_path + "onequestion.html";
            //2.形成字典
            ctemplate::TemplateDictionary root("question");
            root.SetValue("number", q.number);
            root.SetValue("title", q.title);
            root.SetValue("grade", q.grade);
            root.SetValue("desc", q.desc);
            root.SetValue("pre_code", q.header);

            //3.获取渲染html
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(path.c_str(), ctemplate::DO_NOT_STRIP);
            
            //完成渲染
            tpl->Expand(html, &root);
        }
        void Judge()
        {
        }
    };
}